package org.microservice.system.runner;

import lombok.extern.slf4j.Slf4j;
import org.microservice.common.entity.SysZuulRoute;
import org.microservice.common.util.constant.CacheConstant;
import org.microservice.redis.util.RedisService;
import org.microservice.system.service.SysZuulRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 齐丹枫
 * Date: 2018/6/25
 * Time: 10:19
 * To change this template use File | Settings | File Templates.
 * Description:系统启动的时加载路由到缓存中
 */
@Component
@Slf4j
public class SysZuulRouteRunner implements CommandLineRunner{

    @Autowired
    private RedisService redisService;

    @Autowired
    private SysZuulRouteService sysZuulRouteService;


    @Override
    public void run(String... strings) throws Exception {
        if(!redisService.exists(CacheConstant.ZUUL_ROUTE_KEY)){
            List<SysZuulRoute> routes = sysZuulRouteService.getBydelFlag(false);
            redisService.set(CacheConstant.ZUUL_ROUTE_KEY,routes);
            log.info("加载路由到缓存中");

        }

    }
}
